package com.qmrz.nb.common.util;
//

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.NumberUtil;
import com.qmrz.nb.common.domain.Excel;
import com.qmrz.nb.common.domain.ExcelSheet;
import org.apache.commons.lang3.math.NumberUtils;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

//import cn.quevo.xuanniao.core.lang.NumberUtils;
//import cn.quevo.xuanniao.core.util.JsonUtil;

public class MachineAvailabiltilyTools {


    public  Map<String, String>  merge(String preFile, InputStream preInputStream, String curFile, InputStream curInputStream) throws IOException {
        Excel preExcel = null;
        Excel curExcel = null;
        try {
            preExcel = new Excel(preFile, preInputStream);
            curExcel = new Excel(curFile, curInputStream);
            ExcelSheet excelSheet = new ExcelSheet();
            excelSheet.setbeginDataIndex(0);
            excelSheet.setSheetIndex(5);
            List<List<String>> preData = excelSheet.readData(preExcel);
            List<List<String>> curData = excelSheet.readData(curExcel);
            Map<String, String> mergeData = new HashMap<>();

            mergeData.put("curV101", this.getPercent(curData.get(96).get(14)));
            mergeData.put("curV102", this.getPercent(curData.get(100).get(14)));
            mergeData.put("curV111", this.getPercent(curData.get(34).get(14)));
            mergeData.put("curV112", this.getPercent(curData.get(38).get(14)));
            mergeData.put("curV121", this.getPercent(curData.get(2).get(14)));

            mergeData.put("curV131", this.getPercent(curData.get(157).get(14)));
            mergeData.put("curV132", this.getPercent(curData.get(76).get(14)));

            //for (int r = 0; r < preData.size(); r++) {
                /*if ("合计".equalsIgnoreCase(preData.get(r).get(0))) {
                    Map<String, String> map = new HashMap();
                    final Integer cur1 = Convert.toInt(curData.get(r).get(3));
                    final Integer cur2 = Convert.toInt(curData.get(r).get(4));
                    map.put("diff10", (cur1 - cur2) + "");
                    final Integer cur5 = Convert.toInt(curData.get(r).get(7));
                    final Integer cur6 = Convert.toInt(curData.get(r).get(8));
                    map.put("diff12", (cur5 - cur6) + "");
                    map.put("diff13", ( Convert.toInt(curData.get(r).get(9)) - Convert.toInt(curData.get(r).get(10)) ) + "");
                    map.put("diff14", ( Convert.toInt(curData.get(r).get(11)) - Convert.toInt(curData.get(r).get(12)) ) + "");
                    map.put("diff15", ( Convert.toInt(curData.get(r).get(13)) - Convert.toInt(curData.get(r).get(14)) ) + "");
                    map.put("diff16", ( Convert.toInt(curData.get(r).get(15)) - Convert.toInt(curData.get(r).get(16)) ) + "");
                    map.put("diff17", ( Convert.toInt(curData.get(r).get(17)) - Convert.toInt(curData.get(r).get(18)) ) + "");
                    map.put("diff18", ( Convert.toInt(curData.get(r).get(19)) - Convert.toInt(curData.get(r).get(20)) ) + "");
                    mergeData.add(map);
                    break;
                }
                if ( "".equalsIgnoreCase(preData.get(r).get(0))) {
                    break;
                }
                if(Arrays.asList(arr).contains(r)){
                    mergeData.add(this.mergeRowData(preData.get(r), curData.get(r)));
                }*/
            //}
            double a = 1.0; // 我下断点的地方，打在下一行的话 我怕看不见mergeData了
            return mergeData;
        } finally {
            if (preExcel != null) {
                preExcel.close();
            }
            if (curExcel != null) {
                curExcel.close();
            }
        }
    }

    private String getPercent(String string) {
        double dlb = Convert.toDouble(string);
        dlb = dlb * 100d;
        String str = NumberUtil.round(dlb,3) + "";
        return  str;
    };

}
